

#include "atomic_op_namespace.h"

#include <sys/atomic.h>

#ifdef __HAVE_ATOMIC64_OPS

uint64_t
atomic_swap_64(volatile uint64_t *addr, uint64_t new)
{
	uint64_t old;

	do {
		old = *addr;
	} while (atomic_cas_64(addr, old, new) != old);

	return (old);
}

crt_alias(__atomic_exchange_8,_atomic_swap_8)

#undef atomic_swap_64
atomic_op_alias(atomic_swap_64,_atomic_swap_64)
crt_alias(__sync_lock_test_and_set_8,_atomic_swap_64)
#if defined(_LP64)
#undef atomic_swap_ulong
atomic_op_alias(atomic_swap_ulong,_atomic_swap_64)
__strong_alias(_atomic_swap_ulong,_atomic_swap_64)
#undef atomic_swap_ptr
atomic_op_alias(atomic_swap_ptr,_atomic_swap_64)
__strong_alias(_atomic_swap_ptr,_atomic_swap_64)
#endif /* _LP64 */

#endif
